package projectAnalysis.advancedTechAnalyzer;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.InputStream;
import java.util.List;

public class TechFeatureLoader {
    // 从资源目录加载tech-features.json
    public List<TechDefinition> loadFromResource() throws Exception {
        // 读取src/main/resources下的配置文件（JDK 8兼容的流处理）
        try (InputStream is = getClass().getResourceAsStream("/tech-features.json")) {
            if (is == null) {
                throw new RuntimeException("未找到配置文件: src/main/resources/tech-features.json");
            }
            ObjectMapper mapper = new ObjectMapper();
            TechLibrary library = mapper.readValue(is, TechLibrary.class);
            return library.getTechList();
        }
    }

    // 内部包装类（对应JSON结构）
    private static class TechLibrary {
        private List<TechDefinition> techList;

        public List<TechDefinition> getTechList() { return techList; }
        public void setTechList(List<TechDefinition> techList) { this.techList = techList; }
    }
}